<template>
  <div class="dashboard-editor-container">
    <el-alert title="系统通知 乐家物业管理收费增值系统全新升级，正式更名为“乐家智慧物业平台”，带您一起体验高效、简洁的物业工作模式" class="mb10" type="success">
    </el-alert>
    <el-alert <panel-group :counts="counts" @handleSetLineChartData="handleSetLineChartData" />
    <el-row :gutter="10">
      <el-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <div class="title">房屋欠费统计</div>
          <!-- <raddar-chart /> -->
          <el-table :data="tableData">
            <el-table-column prop="id" width="50" label="排行">
              <template slot-scope="scope">{{ scope.$index+1 }}</template>
            </el-table-column>
            <el-table-column prop="data1" label="房屋名称">
            </el-table-column>
            <el-table-column prop="data2" label="欠费周期">
              <template slot-scope="scope">{{ scope.row.data2 }}个月</template>

            </el-table-column>
            <el-table-column prop="data3" label="欠费金额">
              <template slot-scope="scope">{{ scope.row.data2 * 110 }}</template>
            </el-table-column>
          </el-table>
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <div class="title">收入来源分析</div>
          <pie-chart />
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <div class="title">工单处理分析</div>
          <bar-chart />
        </div>
      </el-col>
    </el-row>


  </div>
</template>

<script>
  import PanelGroup from './dashboard/PanelGroup'
  import LineChart from './dashboard/LineChart'
  import RaddarChart from './dashboard/RaddarChart'
  import PieChart from './dashboard/PieChart'
  import BarChart from './dashboard/BarChart'
  import {init} from '@/api/system/index'

  const lineChartData = {
    newVisitis: {
      expectedData: [100, 120, 161, 134, 105, 160, 165],
      actualData: [120, 82, 91, 154, 162, 140, 145]
    },
    messages: {
      expectedData: [200, 192, 120, 144, 160, 130, 140],
      actualData: [180, 160, 151, 106, 145, 150, 130]
    },
    purchases: {
      expectedData: [80, 100, 121, 104, 105, 90, 100],
      actualData: [120, 90, 100, 138, 142, 130, 130]
    },
    shoppings: {
      expectedData: [130, 140, 141, 142, 145, 150, 160],
      actualData: [120, 82, 91, 154, 162, 140, 130]
    }
  }

  export default {
    name: 'Index',
    components: {
      PanelGroup,
      LineChart,
      RaddarChart,
      PieChart,
      BarChart
    },
    data() {
      return {
        counts: [],
        lineChartData: lineChartData.newVisitis,
        tableData: [{
            id: '1',
            data1: ' DS-5-702',
            data2: '36',
            data3: '3960'
          },
          {
            id: '1',
            data1: ' DS-2-402',
            data2: '36',
            data3: '3960'
          },
          {
            id: '1',
            data1: ' DS-1-606',
            data2: '33',
            data3: '3960'
          },
          {
            id: '1',
            data1: ' DS-28-908',
            data2: '33',
            data3: '3960'
          },
          {
            id: '1',
            data1: ' DS-23-772',
            data2: '30',
            data3: '3960'
          },
          {
            id: '1',
            data1: ' DS-33-109',
            data2: '29',
            data3: '3960'
          },
          {
            id: '1',
            data1: ' DS-08-442',
            data2: '28',
            data3: '3960'
          },
          {
            id: '1',
            data1: ' DS-25-41',
            data2: '17',
            data3: '3960'
          },

        ]
      }
    },
    created() {
       this.loadData();
    },
    methods: {
      loadData(){
        init().then(res=>{
          this.counts=res.data
        });
      },
      handleSetLineChartData(item) {
        console.log("item", item)
        this.lineChartData = lineChartData[item.id]
        switch (item.id) {
          case 1:
            this.$router.push({path: '/payfee/report', query: {time: "no"}})
            break;
          case 2:
           this.$router.push({path: 'payfee/balanceRefill', query: {time: "no"}})
            break;
          case 3:
          this.$router.push({path: 'waitress/workOrder', query: {time: "no",id:item.auxiliaryId}})
            break;
          case 4:
          this.$router.push({path: 'waitress/workOrder', query: {time: "no",id:item.auxiliaryId}})
            break;
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
  .title {
    margin-bottom: 20px;
  }

  .dashboard-editor-container {
    padding: 10px;
    background-color: rgb(240, 242, 245);
    position: relative;

    .chart-wrapper {
      background: #fff;
      padding: 16px 16px 0;
      margin-bottom: 32px;
      height: 400px;
      overflow: hidden;
      box-sizing: border-box;
    }
  }

  @media (max-width:1024px) {
    .chart-wrapper {
      padding: 8px;
    }
  }
</style>
